//表单验证
let form = layui.form
form.verify({
    len: [/^\S{6,12}$/, '密码6-12位且不能有空格'],
    diff: function (val) {
        let yuan = $('input[name=oldPwd]').val()
        if (val == yuan) {
            return '不能与原密码相同'
        }
    },
    same: function (a) {
        // a表示输入的重复密码
        //获取密码的内容
        let pwd = $('.pwd').val()
        if (pwd != a) {
            return '两次密码不一致'
        }
    }
 })
//修改密码
$('form').on('submit', function (e) {
    e.preventDefault()
    $.ajax({
        type: 'POST',
        url: '/my/user/updatepwd',
        data: $(this).serialize(),
        success: function (res) {
            if (res.status === 0) {
                localStorage.removeItem('token')
                layer.msg(res.message, { time: 1500 }, function () {
                    window.parent.location.href = '../login.html'
                })
            }else {
                layer.msg(res.message)
                }
        }
    })
})